import { AxiosInstance } from "axios";
import axios from 'axios'

const instance: AxiosInstance = axios.create({
  baseURL: 'http://localhost:8081/user',
  timeout: 2000,
  headers: {
    'Content-type': 'application/json',
    // 'Access-Control-Allow-Origin': 'http://localhost:8080',
    // 'Access-Control-Allow-Credentials': 'true'
  },
  withCredentials: true
})

async function currentUser() {
  return 1
}

async function login(request: LoginRequest) {
  let response = await instance.post('/login', JSON.stringify(request))

  return response.data
}

async function register(user: User) {
  let response = await instance.post('/register', JSON.stringify(user))
  return response.data
}

async function exit(user: User) {
  let response = await instance.post('/exit', JSON.stringify(user))
  return response.data
}

export {
  currentUser,
  login,
  register,
  exit
}